<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Bootstrap Admin Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="/dt200_admin/Public/home/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <!--<link href="_PUBLIC__/font/css/font-awesome.min.css" rel="stylesheet" type="text/css">-->

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	
</head>
	<body>
		<div class="container-fluid">
        <!-- Page Heading -->
	        <div class="row">
				<div class="col-md-12">
					<ol class="breadcrumb">
						<li class="active">
							<i class="fa fa-fw fa-edit"></i>
							产品管理
						</li>
					</ol>
				</div>
			</div>
			<div class="row">
				<ul class="nav nav-tabs" role="tablist">
				    <li role="presentation" class="active"><a href="#message" aria-controls="home" role="tab" data-toggle="tab">基本信息</a></li>
			 	</ul>
			 	<div class="tab-content col-xs-12">
					<div role="tabpanel" class="tab-pane active" id="message">
						<div class="row">
							<div class="col-sm-10">
								<form id="zyn-form-add" class="form-horizontal">
									<div class="form-group" style="display: none;">
										<label for="lc-input-device_id" class="control-label col-sm-2">设备id</label>
										<div class="col-sm-3">
											<input id="lc-input-device_id" class="form-control" type="text" name="device_id" value="<?php echo ($device["device_id"]); ?>"/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "device_id">*设id</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-device_name" class="control-label col-sm-2">设备名</label>
										<div class="col-sm-3">
											<input id="lc-input-device_name" class="form-control" type="text" name="device_name" value="<?php echo ($device["device_name"]); ?>"/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "device_name">*命令名</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-url" class="control-label col-sm-2">路径</label>
										<div class="col-sm-3">
											<input id="lc-input-url" class="form-control" type="text" name="url" value="<?php echo ($device["url"]); ?>"/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "url">*url</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-ip" class="control-label col-sm-2">IP</label>
										<div class="col-sm-3">
											<input id="lc-input-ip" class="form-control" type="text" name="ip" value="<?php echo ($device["ip"]); ?>"/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "ip">*ip</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-port" class="control-label col-sm-2">端口</label>
										<div class="col-sm-3">
											<input id="lc-input-port" class="form-control" type="text" name="port" value="<?php echo ($device["port"]); ?>"/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "port">*port</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-drive_id" class="control-label col-sm-2">驱动</label>
										<div class="col-sm-3" id="lc-div-drive">
											<?php if(is_array($drive)): $i = 0; $__LIST__ = $drive;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$com): $mod = ($i % 2 );++$i;?><label class="checkbox-inline">
												    <input type="checkbox" class="checkbox-drive" value="<?php echo ($com["drive_id"]); ?>" <?php if(in_array(($com["drive_id"]), is_array($device_drive)?$device_drive:explode(',',$device_drive))): ?>checked<?php endif; ?>><?php echo ($com["drive_name"]); ?>
												</label><?php endforeach; endif; else: echo "" ;endif; ?>
										</div>
										<div class="col-sm-3">
											<p class="zyn-p-validate-result p-no-margin" attr-validate = "drive_id">*</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-command_id" class="control-label col-sm-2">命令</label>
										<div class="col-sm-3" id="lc-div-command">
											<?php if(is_array($command)): $i = 0; $__LIST__ = $command;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$and): $mod = ($i % 2 );++$i;?><label class="checkbox-inline">
												    <input type="checkbox" class="checkbox-command" value="<?php echo ($and["command_id"]); ?>" <?php if(in_array(($and["command_id"]), is_array($device_command)?$device_command:explode(',',$device_command))): ?>checked<?php endif; ?>><?php echo ($and["command_name"]); ?>
												</label><?php endforeach; endif; else: echo "" ;endif; ?>
										</div>
										<div class="col-sm-3">
											<p class="zyn-p-validate-result p-no-margin" attr-validate = "command_id">*</p>
										</div>
									</div>
								</form>
							</div>	
						</div>
					</div>
 				</div>
 				<div class="col-xs-10 col-xs-offset-2">
 					<button class="btn btn-primary" id="xx-btn-save">提交保存</button>
 					<button class="btn btn-primary" id="xx-btn-return">返回上一页</button>
 				</div>
			</div>
		</div>
		
	</body>
	<script src="/dt200_admin/Public/home/js/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="/dt200_admin/Public/home/js/bootstrap.min.js"></script>
	<script>
    $(function() {
    	
    });
    $("#xx-btn-return").click(function(){
    	location.href = "/dt200_admin/index.php/Home/Admin/index";
    });
    $("#xx-btn-save").click(function(){
    	var dataDrive = [];
    	var dataCommand = [];
    	$("#lc-div-drive").find(":checkbox:checked").each(function(){
		　　dataDrive.push($(this).val())
		});
		$("#lc-div-command").find(":checkbox:checked").each(function(){
		　　dataCommand.push($(this).val())
		});
		$.ajax({
			type:"post",
			url:"<?php echo U('Device/reviseDeviceInfo');?>",
			data:{
				'device_id' : $("#lc-input-device_id").val(),
				'device_name' : $("#lc-input-device_name").val(),
				'url' : $("#lc-input-url").val(),
				'ip' : $("#lc-input-ip").val(),
				'port' : $("#lc-input-port").val(),
				'drive_id':dataDrive,
				'command_id':dataCommand
			},
			dataType:'json',
			success:function(result){
				//链接服务器其成功
				if(result.status == 1){
					//成功
					return location.href = "<?php echo U('Device/index');?>";
				}else{
					alert(result.msg);
				}
				
			},
			
		});
    });
    </script>
</html>